﻿using System.Collections.Generic;

namespace Miao.ML
{
	public class GenericArgumentData : WinMLData, IGeneric, IQualifiedName
	{
		internal readonly List<IGeneric> genericArgumentList = new List<IGeneric>();

		public sealed override DataType type => DataType.GenericArgument;

		public bool isGenericType => genericArgumentList.Count > 0;

		public int genericArgumentCount => genericArgumentList.Count;

		public IEnumerable<IGeneric> genericArguments => genericArgumentList;

		public string openTypeName { get; set; }

		public string qualifiedName { get; set; }

		public IGeneric GetGenericArgument(int index)
		{
			return genericArgumentList[index];
		}

		public void AddGenericArgument(IGeneric typeData)
		{
			genericArgumentList.Add(typeData);
		}

		public override string ToString()
		{
			if (!isGenericType)
			{
				return qualifiedName;
			}
			string text = $"{qualifiedName}{'<'}";
			foreach (IGeneric genericArgument in genericArgumentList)
			{
				text += $"{genericArgument}{','}";
			}
			return $"{text.Remove(text.Length - 1, 1)}{'>'}";
		}
	}
}
